//
//  WJCollectionReusableView.m
//  CollectionViewDemo
//
//  Created by wangjie on 2018/6/7.
//  Copyright © 2018年 I just want to be a quiet and handsome man. All rights reserved.
//

#import "WJLiveCourseCollectionHeader.h"
#import <Masonry.h>
@interface WJLiveCourseCollectionHeader ()
@end

@implementation WJLiveCourseCollectionHeader

-(UILabel *)bottomLabel{
    if (!_bottomLabel) {
        _bottomLabel = [[UILabel alloc]init];
        _bottomLabel.textColor = UIColor.darkGrayColor;
        _bottomLabel.font = [UIFont systemFontOfSize:12];
    }
    return _bottomLabel;
}

-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = UIColor.darkGrayColor;
        _titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return _titleLabel;
}

-(UIButton *)allButton{
    if (!_allButton) {
        _allButton = [[UIButton alloc]init];
        [_allButton setTitle:@"选择" forState:UIControlStateNormal];
        [_allButton setTitle:@"取消选择" forState:UIControlStateSelected];
        [_allButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
        [_allButton setImage:[UIImage imageNamed:@"normal"] forState:UIControlStateNormal];
        [_allButton setImage:[UIImage imageNamed:@"sel"] forState:UIControlStateSelected];
        [_allButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _allButton;
}


-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        [self addSubview:self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.right.equalTo(@(-100));
            make.top.equalTo(@10);
        }];
        
        [self addSubview:self.bottomLabel];
        [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_left);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        }];
        // 10 + 15 + 10 + 12 + 10
        
        [self addSubview:self.allButton];
        [self.allButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-10));
            make.top.equalTo(@10);
        }];
        
        

    }
    return self;
    
}


- (void)click:(UIButton *)button{
    button.selected = !button.selected;

    if (button.selected) {
        if (self.confirmBlock) {
            self.confirmBlock();
        }
    }else{
        if (self.cancelBlock) {
            self.cancelBlock();
        }
    }
}



@end
